<template>
	<view class="uni-content">
		<view class="head-nav">
			<view :class="listIndex==y?'activite':''" @click="checkListIndex(y)" v-for="(x,y) in navList" :key="y">{{x}}</view>
		</view>
		<view class="cu-list menu sm-border"  v-if="listIndex == 0">
			<view class="cu-item"  @click="toUrl('/pages/msg/detail',item.id)" v-for="(item, index) in articleList" :key="index">
				<view class="content">
					<view class="readed_icon"></view>
					<view class="title">{{ item.title }}</view>
					<view class="time">{{ item.create_time }}</view>
				</view>
			</view>
		</view>
		<view  v-else class="cu-list menu sm-border">
			<view class="cu-item"  @click="toUrl('/pages/msg/msg',item.id)" v-for="(item, index) in articleList" :key="index">
				<view class="content">
					<view v-if="item.reply_content == null" class="unreply_icon"></view>
					<view>{{ item.content }}</view>
					<view>{{ item.create_time }}</view>
				</view>
			</view>
		</view>
		<view v-if="listIndex == 1">
			<view v-if="showbtn == 1" style="text-align: center">暂无反馈</view>
		</view>
		<view v-if="showbtn == 1" class="submit_order" @click="toUrl('/pages/msg/feedback')">提交反馈</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				classify_id:1,
				classifyInfo:[],
				articleList:[],
				navList:["系统消息","意见反馈"],
				navIndex:1,
				listIndex:0,
				page: 1,
				showbtn:0,
			};
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.getData();
		},
		methods: {
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				let id = this.classify_id;
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['id='+id,'timestamp='+timestamp]);
				this.helper.req({
					api:"getHelpClassify",
					timestamp:timestamp,
					data:{id:id},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					// console.log(res.data);
					this.classifyInfo = res.data.data.classifyInfo;
					this.articleList = res.data.data.articleList;
					uni.setNavigationBarTitle({
						title: this.classifyInfo.name
					});
					
					uni.hideLoading();
				})
			},
			getMsg:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				let page = this.page;
				let info = uni.getStorageSync("userinfo");				
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['page='+page,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"getMsgList",
					timestamp:timestamp,
					data:{page:page,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					// console.log(res.data);
					//this.title = res.data.data[0].title;
					this.articleList = res.data.data.list;
					if (this.articleList.length === 0) {
					    this.showbtn=1
						console.log('1长度',this.articleList.length)
					} else {
					    this.showbtn=1
						console.log('0长度',this.articleList.length)
					}
					uni.setNavigationBarTitle({
						title: '意见反馈'
					});
					
					uni.hideLoading();
				})
			},						
			checkListIndex(index){
				
				this.listIndex =index;
				if(this.listIndex == 0){
					this.articleList = [],
					this.page = 1,
					this.lastPage = 0
					this.getData();
					this.showbtn=0
					console.log('执行了listindex'+this.listIndex)
				}else{
					this.articleList = [],
					this.page = 1,
					this.lastPage = 0					
					this.getMsg();
					this.showbtn=1
					console.log('执行了listindex'+this.listIndex)
				}
				
				
			  },
			//链接
			toUrl:function(url,id){
				url +='?id='+id;
				// console.log(url);
				uni.navigateTo({
					url: url,
				});	
			},
		},
	};
</script>

<style lang="scss">
	page{
		color: #56595d;
		background-color: #ddeafd;
		overflow: hidden;
	}
	.uni-content{
		background-color: #fff;
		position: absolute;
		top: 5vh;
		left: 5vw;
		bottom: 0;
		right: 5vw;
		border-radius: 20rpx 20rpx 0 0;
		box-shadow: 0 0 10px 5px rgba(182, 203, 242, 0.3);
	}
	.head-nav{
    display: flex;
    align-items: center;
	}
	.content{
			font-size: 0.64rem;
	    color: #666;
	    padding: 0.9rem 0;
	    margin: 0 0.67rem;
	    border-bottom: min(0.267px, 2.048px) solid #eeeeee;
	    display: flex;
	    align-items: center;
			.title{
				flex: 1;
			}
			.reply_icon::before {content: '已回复';}
			.unreply_icon::before {content: '处理中';}
			.reply_icon::before {content: '已读';}
			.reply_icon, .unreply_icon, .readed_icon {
				background: linear-gradient( 180deg, #9dc1ff 0%, #508ffd 100%);
				padding: 0 10rpx;
				line-height: 32rpx;
				font-size: 24rpx;
				color: #fff;
				border-radius: 10rpx 0  0 10rpx;
				margin-right: 5rpx;
				&::before {
					content: '已读';
				}
			}
	}
	.head-nav>.activite{
		color: #4f8dfd;
	}
	.head-nav>.activite::after{
		content: '';
		position: absolute;
		bottom: 0;
		left: calc(50% - 50rpx);
		width: 100rpx;
		height: 5rpx;
		border-radius: 5rpx;
		background: #4f8dfd;
	}
	.head-nav>view{
		flex: 1;
    text-align: center;
		padding: 20rpx 0;
		font-size: 32rpx;
		position: relative;
	}
	.submit_order{
		width: 92%;
		padding: 12px;
		background: linear-gradient( 180deg, #9dc1ff 0%, #508ffd 100%);
		color: #fff;
		font-size: 18px;
		text-align: center;
		border-radius: 6px;
		position: fixed;
		bottom: 10px;
		left: 4%;
	}
	
</style>
